Imports Microsoft.VisualBasic
Imports System
Imports System.WEB
Imports System.ComponentModel
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Data
Imports System.Data.OleDb
Public Class cTbPagesZusatz
    Dim mstrConnString As String
    Public Function GetDataSet(Optional ByVal StrSelect As String = "*", Optional ByVal strWhere As String = "LNr >= 0", Optional ByVal strOrder As String = "spaces") As DataSet
        Dim Sql As String = "SELECT " & StrSelect & " FROM tbl_pages_zusatz WHERE " & strWhere & " ORDER BY " & strOrder
        Dim myConn2 As New OleDbConnection(mstrConnString)
        Dim myCmd2 As New OleDbCommand
        myCmd2.Connection = myConn2
        Dim myAdapter As New OleDbDataAdapter()
        myAdapter.SelectCommand = myCmd2

        GetDataSet = New DataSet
        myCmd2.CommandText = Sql
        myAdapter.Fill(GetDataSet, "Table")

        myConn2.Close()
    End Function

    Public Function GetFelder(ByVal LNr As Integer, Optional ByVal pWhere As String = "") As DataView
        Dim myConn As New OleDbConnection(mstrConnString)
        myConn.Open()

        ' Kommando-Objekt vorbereiten
        Dim cmd As New OleDbCommand()
        cmd.Connection = myConn
        ' Adapter-Objekt vorbereiten
        Dim myAdapter As New OleDbDataAdapter()
        myAdapter.SelectCommand = cmd
        ' DataSet-Objekt vorbereiten
        Dim myDS As New DataSet()

        ' Tabelle "Pages" einlesen
        Dim Sql As String
        If pWhere <> "" Then
            Sql = "SELECT * FROM tbl_pages_Zusatz WHERE " & pWhere
        Else
            Sql = "SELECT * FROM tbl_pages_Zusatz WHERE LNr = " & LNr
        End If
        cmd.CommandText = Sql
        myAdapter.Fill(myDS, "Pages_Zusatz")

        GetFelder = New DataView(myDS.Tables("Pages_Zusatz"))
        myDS.Dispose()
        myConn.Close()
    End Function

    Public Sub Update(ByVal lNr As Integer, Optional ByVal cnr As String = Nothing, _
                                                    Optional ByVal linktexte As String = Nothing, _
                                                    Optional ByVal spaces As String = Nothing, _
                                                    Optional ByVal linkurl As String = Nothing)
        Dim Sql As String = ""
        If Not cnr = Nothing Then Sql += ", Cnr = '" & cnr & "'"
        If Not linktexte = Nothing Then Sql += ", linktexte = '" & linktexte & "'"
        If Not spaces = Nothing Then Sql += ", spaces = '" & spaces & "'"
        If Not linkurl = Nothing Then Sql += ", linkurl = '" & linkurl & "'"
        If Sql.Length > 0 Then Sql = "UPDATE tbl_pages_zusatz SET " & Sql.Substring(2)
        Sql += " WHERE LNr = " & lNr
        Dim myConn As New OleDbConnection(mstrConnString)
        Dim Cmd As New OleDbCommand(Sql, myConn)
        myConn.Open()
        Cmd.ExecuteReader()
        myConn.Close()
    End Sub

    Public Sub Insert(Optional ByVal cnr As String = Nothing, _
                      Optional ByVal linktexte As String = Nothing, _
                      Optional ByVal linkurl As String = Nothing, _
                      Optional ByVal spaces As String = Nothing)
        Dim F As String = ""
        Dim W As String = ""
        Dim Sql As String = ""
        If Not cnr = Nothing Then F += ",Cnr" : W += ",'" & cnr & "'"
        If Not linktexte = Nothing Then F += ",linktexte" : W += ",'" & linktexte & "'"
        If Not linkurl = Nothing Then F += ",linkurl" : W += ",'" & linkurl & "'"
        If Not spaces = Nothing Then F += ",spaces" : W += ",'" & spaces & "'"
        If F.Length > 0 Then
            Sql = "INSERT INTO tbl_pages_zusatz (" & F.Substring(1) & ") VALUES(" & W.Substring(1) & ")"
            Dim myConn As New OleDbConnection(mstrConnString)
            Dim Cmd As New OleDbCommand(Sql, myConn)
            myConn.Open()
            Cmd.ExecuteReader()
            myConn.Close()
        End If
    End Sub

    Public Sub Delete(ByVal LNr As Integer)
        Dim strSQL As String = "DELETE * FROM tbl_pages_zusatz WHERE LNr = " & LNr & ";"
        Dim dconn As New OleDbConnection(mstrConnString)
        Dim iCmd As New OleDbCommand(strSQL, dconn)
        dconn.Open()
        iCmd.ExecuteReader()
        dconn.Close()
    End Sub

    Public Sub New(ByVal strConnString As String)
        mstrConnString = strConnString
    End Sub
End Class



